package org.example.framework.protocol.http;

import org.example.framework.Invocation;
import org.example.framework.Invoker;
import org.example.framework.Protocol;
import org.example.framework.ServerUrl;
import org.example.framework.register.LocalRegister;
import org.example.framework.register.RemoteRegister;
import org.example.provider.api.HelloService;
import org.example.provider.impl.HelloServiceImpl;

/**
 * @author shenguangyang
 */
public class HttpProtocol implements Protocol {
//    @Override
//    public void start(ServerUrl serverUrl) {
//        new HttpServer().start(serverUrl.getHostname(), serverUrl.getPort());
//    }
//
//    @Override
//    public Object send(ServerUrl serverUrl, Invocation invocation) {
//        return new HttpClient().send(serverUrl.getHostname(), serverUrl.getPort(), invocation);
//    }


    @Override
    public void export(ServerUrl serverUrl) {
        // 本地注册
        LocalRegister.register(serverUrl.getInterfaceName(), "1", serverUrl.getImplClass());
        // 注册中心注册
        RemoteRegister.register(serverUrl.getInterfaceName(), serverUrl);
        new HttpServer().start(serverUrl.getHostname(), serverUrl.getPort());
    }

    @Override
    public Invoker refer(ServerUrl serverUrl) {
        return new HttpInvoker(serverUrl);
    }
}
